//
//  XSPhotosManager.h
//  AudioVideo
//
//  Created by xueshan1 on 2019/9/11.
//  Copyright © 2019 xueshan1. All rights reserved.
//

#import <Foundation/Foundation.h>

typedef NS_ENUM(NSUInteger, XSAssetMediaType) {
    XSAssetMediaTypeUnknown,
    XSAssetMediaTypeImage,
    XSAssetMediaTypeGif,
    XSAssetMediaTypeLivePhoto,
    XSAssetMediaTypeVideo,
    XSAssetMediaTypeAudio,
    XSAssetMediaTypeNetImage,
    XSAssetMediaTypeNetVideo,
};


/**
 相册管理
 */
@class XSPhotoModel,XSAlbumListModel;
@interface XSPhotosManager : NSObject

//存储到相册
+ (void)saveToPhotoLibrary:(NSURL *)outputURL completion:(void(^)(NSError *error))completion;

#pragma mark - 保存图片到系统相册
+ (void)saveImageToAblum:(UIImage *)image completion:(void (^)(BOOL success, PHAsset *asset))completion;
#pragma mark - 保存视频到系统相册
+ (void)saveVideoToAblum:(NSURL *)url completion:(void (^)(BOOL success, PHAsset *asset))completion;



+ (instancetype)shareInstance;
@property(nonatomic,copy)void(^selectedPhtotosBlock)(NSArray<XSPhotoModel *> *selectedPhotos);
//图片选择器
+ (void)showImagePickerController:(UIViewController *)targeVC selectVideo:(BOOL)selectVideo complete:(void(^)(NSArray<XSPhotoModel *>  *array))complete;
+ (void)showImagePickerController:(UIViewController *)targeVC selectVideo:(BOOL)selectVideo maxCount:(NSInteger)maxCount complete:(void(^)(NSArray<XSPhotoModel *>  *array))complete;

/**
 * @brief 设置排序模式
 */
+ (void)setSortAscending:(BOOL)ascending;

#pragma mark - 获取 "相机胶卷" 相册
+ (void)getCameraRollAlbumListAllowSelectVideo:(BOOL)allowSelectVideo allowSelectImage:(BOOL)allowSelectImage complete:(void (^)(XSAlbumListModel * albumModel))complete;

#pragma mark - 获取 所有相册 列表
+ (void)getAlbumList:(BOOL)allowSelectVideo allowSelectImage:(BOOL)allowSelectImage complete:(void(^)(NSArray<XSAlbumListModel *>* albumList))complete;



#pragma mark - album
/**
 获取 "相机胶卷" 相册
 
 @param allowSelectVideo 选视频
 @param allowSelectImage 选图片
 @return 相册model
 */
+ (XSAlbumListModel *)getCameraRollAlbumList:(BOOL)allowSelectVideo allowSelectImage:(BOOL)allowSelectImage;

#pragma mark - model
//获取相册model
//+ (XSAlbumListModel *)getAlbumListModelWithTitle:(NSString *)title fetchResult:(PHFetchResult <PHAsset *>*)fetchResult allowSelectVideo:(BOOL)allowSelectVideo allowSelectImage:(BOOL)allowSelectImage;

//获取某个相册内的limit个数的资源
//+ (NSArray<XSPhotoModel *>*)getPhotoModelsWithFetchResult:(PHFetchResult<PHAsset *>*)fetchResult allowSelectVideo:(BOOL)allowSelectVideo allowSelectImage:(BOOL)allowSelectImage allowSelectGif:(BOOL)allowSelectGif allowSelectLivePhoto:(BOOL)allowSelectLivePhoto limitCount:(NSInteger)limit;


#pragma mark - image
//获取asset对应的图片
//获取原图
+ (void)requestOriginalImageForAsset:(XSPhotoModel *)photoModel progressHandler:(void (^ _Nullable)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler completion:(void (^)(UIImage *image, NSDictionary *dic))completion;

+ (PHImageRequestID)requestImageWithModel:(XSPhotoModel *)photoModel completion:(void (^)(UIImage *image, NSDictionary *info))completion;

//图片
+ (PHImageRequestID)requestImageForAsset:(PHAsset *)asset size:(CGSize)size progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler completion:(void (^)(UIImage *image, NSDictionary *info))completion;

//图片大小
//全部
+ (void)getPhotosBytesWithArray:(NSArray<XSPhotoModel *> *)photos completion:(void (^)(NSString *photosBytes))completion;
//一个
+ (void)getPhotosBytesWithModel:(XSPhotoModel*)model completion:(void (^)(NSString *photosBytes))completion;



#pragma mark - Video
//返回url, 将视频写入tmp文件, 较慢
+ (void)requestVideoURL_ForAsset:(PHAsset *)asset completion:(void (^)(NSURL *videoUrl, NSDictionary *info))completion;
//返回playItem, 用于播放
+ (void)requestVideoPlayItem_ForAsset:(PHAsset *)asset progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler completion:(void (^)(AVPlayerItem * _Nullable playerItem, NSDictionary *info))completion;
//返回asset, 用于处理音轨/视频贵轨
+ (void)requestVideoAVAsset_ForAsset:(PHAsset *)asset progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler completion:(void (^)(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary *info))completion;


@end

 
